package mobi.pooper.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class PicsDbHelper extends SQLiteOpenHelper {
        private static final String DATABASE_NAME = "pooperdata";

        private static final int DATABASE_VERSION = 1;

        // Database creation sql statement
        private static final String DATABASE_CREATE = "create table " + PicsDbAdapterImpl.DATABASE_TABLE + " (_id integer primary key autoincrement, "
                + PicsDbAdapterImpl.KEY_NAME + " text not null, " 
                + PicsDbAdapterImpl.KEY_DESCRIPTION + " text not null, " 
                + PicsDbAdapterImpl.KEY_SUCCESSES_NUMBER + " integer not null, "
                + PicsDbAdapterImpl.KEY_FAILS_NUMBER + " integer not null);";

        public PicsDbHelper(Context context) {
                super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }

        // Method is called during creation of the database
        @Override
        public void onCreate(SQLiteDatabase database) {
                database.execSQL(DATABASE_CREATE);
        }

        // Method is called during an upgrade of the database, e.g. if you increase
        // the database version
        @Override
        public void onUpgrade(SQLiteDatabase database, int oldVersion,
                        int newVersion) {
                Log.w(PicsDbHelper.class.getSimpleName(),
                                "Upgrading database from version " + oldVersion + " to "
                                + newVersion + ", which will destroy all old data");
                database.execSQL("DROP TABLE IF EXISTS " + PicsDbAdapterImpl.DATABASE_TABLE);
                onCreate(database);
        }
}
